package com.flying.invest.strategy.service;

import java.util.Date;

import com.flying.common.annotation.DaoCreate;
import com.flying.common.annotation.DaoQuery;
import com.flying.common.annotation.DaoRemove;
import com.flying.common.annotation.DaoUpdate;
import com.flying.common.annotation.Transaction;
import com.flying.common.util.Codes;
import com.flying.framework.annotation.MethodInfo;
import com.flying.framework.annotation.Param;
import com.flying.framework.annotation.Service;
import com.flying.framework.exception.AppException;
import com.flying.framework.model.ActionResult;
import com.flying.framework.model.QueryResult;
import com.flying.framework.service.AbstractService;
import com.flying.invest.strategy.model.StrategyAutoPlanDetail;

@Service(value="StrategyAutoPlanDetailService", desc="定投明细")
public class StrategyAutoPlanDetailService extends AbstractService{
        
	@MethodInfo("新增")
	@DaoCreate(entity=StrategyAutoPlanDetail.ENTITY_NAME)
	public StrategyAutoPlanDetail create(
			@Param(value=StrategyAutoPlanDetail.USER_ID, required=true,	desc="所属用户") Long user_id,
			@Param(value=StrategyAutoPlanDetail.TYPE_ID, required=true,	desc="策略类型") Long type_id,
			@Param(value=StrategyAutoPlanDetail.INVEST_ID, required=true,	desc="投资项目") Long invest_id,
			@Param(value=StrategyAutoPlanDetail.STRATEGY_ID, required=true,	desc="策略ID") Long strategy_id,
			
			@Param(value=StrategyAutoPlanDetail.NUM, required=true,	desc="期数") Integer num,
			@Param(value=StrategyAutoPlanDetail.PLAN_DATE, required=true,	desc="计划日期") Date plan_date,
			@Param(value=StrategyAutoPlanDetail.PLAN_AMOUNT, required=false,	desc="计划金额") Double plan_amount,
			@Param(value=StrategyAutoPlanDetail.PLAN_QUANTITY, required=false,	desc="计划数量") Double plan_quantity
		) {
		return null;
	}

	@MethodInfo("修改")
	@DaoUpdate(entity=StrategyAutoPlanDetail.ENTITY_NAME)
	public ActionResult update(
			@Param(value=StrategyAutoPlanDetail.DETAIL_ID, required=true,	desc="ID") Long detail_id,
			@Param(value=StrategyAutoPlanDetail.USER_ID, required=true,	desc="所属用户") Long user_id,
			@Param(value=StrategyAutoPlanDetail.TYPE_ID, required=true,	desc="策略类型") Long type_id,
			@Param(value=StrategyAutoPlanDetail.INVEST_ID, required=true,	desc="投资项目") Long invest_id,
			@Param(value=StrategyAutoPlanDetail.STRATEGY_ID, required=true,	desc="策略ID") Long strategy_id,
			@Param(value=StrategyAutoPlanDetail.NUM, required=true,	desc="期数") Integer num,
			@Param(value=StrategyAutoPlanDetail.PLAN_DATE, required=true,	desc="计划日期") Date plan_date,
			@Param(value=StrategyAutoPlanDetail.PLAN_AMOUNT, required=false,	desc="计划金额") Double plan_amount,
			@Param(value=StrategyAutoPlanDetail.PLAN_QUANTITY, required=false,	desc="计划数量") Double plan_quantity,
			@Param(value=StrategyAutoPlanDetail.ACTUAL_DATE, required=false,	desc="实际日期") Date actual_date,
			@Param(value=StrategyAutoPlanDetail.ACTUAL_AMOUNT, required=false,	desc="实际金额") Double actual_amount,
			@Param(value=StrategyAutoPlanDetail.ACTUAL_QUANTITY, required=false,	desc="实际数量") Double actual_quantity,
			@Param(value=StrategyAutoPlanDetail.ACTUAL_PRICE, required=false,	desc="实际价格") Double actual_price,
			@Param(value=StrategyAutoPlanDetail.TRANSACTION_ID, required=false,	desc="交易ID") Long transaction_id
			
		) {
		
		return null;
	}

	@MethodInfo("修改")
	@DaoUpdate(entity=StrategyAutoPlanDetail.ENTITY_NAME)
	public ActionResult updateByTransaction(
			@Param(value=StrategyAutoPlanDetail.DETAIL_ID, required=true,	desc="ID") Long detail_id,
			@Param(value=StrategyAutoPlanDetail.ACTUAL_DATE, required=true,	desc="实际日期") Date actual_date,
			@Param(value=StrategyAutoPlanDetail.ACTUAL_AMOUNT, required=true,	desc="实际金额") Double actual_amount,
			@Param(value=StrategyAutoPlanDetail.ACTUAL_QUANTITY, required=true,	desc="实际数量") Double actual_quantity,
			@Param(value=StrategyAutoPlanDetail.ACTUAL_PRICE, required=false,	desc="实际价格") Double actual_price,
			@Param(value=StrategyAutoPlanDetail.TRANSACTION_ID, required=true,	desc="交易ID") Long transaction_id
		) {
		
		return null;
	}

	@MethodInfo("删除")
	@Transaction
	public ActionResult removeByStrategyId(
			@Param(value=StrategyAutoPlanDetail.STRATEGY_ID, required=true,	desc="策略ID") Long strategy_id) {
		var details = this.findByStrategyId(strategy_id).getRows();
		details.stream().forEach(x -> {
			if(x.getActualAmount() != null) throw new AppException("0101", "策略已经产生交易，不能修改！");
			this.removeById(x.getDetailId());
		});
		return null;
	}

	@MethodInfo("删除")
	@DaoRemove(entity=StrategyAutoPlanDetail.ENTITY_NAME)
	protected ActionResult removeById(
			@Param(value=StrategyAutoPlanDetail.DETAIL_ID, required=true,	desc="ID") Long detail_id) {
		return null;
	}

	@MethodInfo("搜索")
	@DaoQuery(entity=StrategyAutoPlanDetail.ENTITY_NAME, pageable=true, modelClass=StrategyAutoPlanDetail.class)
	public QueryResult<StrategyAutoPlanDetail> findAll(
			@Param(value=StrategyAutoPlanDetail.STRATEGY_ID, required=true,	desc="策略ID") Long strategy_id,
			@Param(value=Codes.PAGE_NUM, 	required=false, desc="分页页号，默认0") int page,
			@Param(value=Codes.PAGE_SIZE, 	required=false, desc="分页大小，默认10") int rows) {
		return null;
	}

	@MethodInfo("搜索")
	@DaoQuery(entity=StrategyAutoPlanDetail.ENTITY_NAME, pageable=false, modelClass=StrategyAutoPlanDetail.class, osql = "ORDER BY num")
	public QueryResult<StrategyAutoPlanDetail> findByStrategyId(
			@Param(value=StrategyAutoPlanDetail.STRATEGY_ID, required=true,	desc="策略ID") Long strategy_id) {
		return null;
	}

	@MethodInfo("查询")
	@DaoQuery(entity=StrategyAutoPlanDetail.ENTITY_NAME, single=true, throwsNotFoundException=true )
	public StrategyAutoPlanDetail findById(
			@Param(value=StrategyAutoPlanDetail.DETAIL_ID, required=true,	desc="ID") Long detail_id
		) {
		return null;
	}

}